<?php
/**
 * @package   auto_occasion
 * @subpackage 
 * @author    CMS
 * @copyright 2011
 * @license    All rights reserved
 */
require_once(LIB_PATH.'phpMailer/class.phpmailer.php');


/**
 * Classe permettant de gerer les croteres des acheteurs non trouvé et lui proposer ar mail quand les critères seront dispo
 *
 */
class acheteurCritereSrv {


    /**
     * Fonction permettant d'ajouter
     * @return object $acheteur
     *
     */
    public static function ajouter ($acheteur) {
        // instanciation de la factory
        $maFactory = jDao::get("commun~ao_acheteur_critere");
        $records   = jDao::createRecord("commun~ao_acheteur_critere");

        $records->nom      = $acheteur->nom;
        $records->prenom   = $acheteur->prenom;
        $records->email    = $acheteur->email;
        $records->critere  = $acheteur->critere;
        
        return $maFactory->insert($records);

    }
    /**
     * Fonction permettant d'ajouter
     * @return object $acheteur
     *
     */
    public static function deleteMultiple ($ids) {
         $sql = " DELETE FROM ao_acheteur_critere WHERE id IN ('".implode(',', $ids)."')";
         $cnx = jDb::getConnection();
         $cnx->exec($sql);
    }


    /**
     * Envoi de mail
     *
     */
     public function sendMail($datas) {

        $mail = new PHPmailer();
        $mail->IsSMTP();
        $mail->IsHtml(true);
        $mail->AddAddress($datas->vendeurMail);
        $mail->Host         = $GLOBALS['gJConfig']->mailer['smtpHost'];
        $mail->Port         = $GLOBALS['gJConfig']->mailer['smtpPort'];
        $mail->Username     = 'Auto Occasion';
        $mail->From         = $GLOBALS['gJConfig']->mailer['webmasterEmail'];
        $mail->FromName     = 'Auto - occasion';
        $mail->Subject      = 'Auto Occasion : Annonce';
    
        $mail->Body         = utf8_decode($datas->message) ;
        
        if (!$mail->Send()){
          echo $mail->ErrorInfo;
          die('Sending mail - Error');
        }
        
        $mail->SmtpClose();
        $mail->ClearAddresses();
        unset($mail);
        
     }

}